﻿using Microsoft.Phone.Shell;
using System;
using System.ComponentModel;

namespace SMARTMobile.WinPhone
{
    public class PhoneApplicationBarIconButton : IApplicationBarIconButton, INotifyPropertyChanged
    {
        #region Fields

        private bool _isEnabled;
        private string _text;
        private Uri _iconUri;

        #endregion

        #region Constructors

        public PhoneApplicationBarIconButton(string iconUrl, string text, bool isEnabled)
        {
            Text = text;
            _isEnabled = isEnabled;
            IconUri = new Uri(iconUrl, UriKind.Relative);
        }

        public PhoneApplicationBarIconButton(string iconUrl, string text)
            : this(iconUrl, text, true)
        {
        }

        #endregion

        public event PropertyChangedEventHandler PropertyChanged;

        #region Properties

        public bool IsEnabled
        {
            get { return _isEnabled; }
            set { _isEnabled = value; NotifyPropertyChanged("IsEnabled"); }
        }

        public string Text
        {
            get { return _text; }
            set { _text = value; NotifyPropertyChanged("Text"); }
        }

        public event EventHandler Click;

        public Uri IconUri
        {
            get { return _iconUri; }
            set { _iconUri = value; NotifyPropertyChanged("IconUri"); }
        }

        #endregion

        private void NotifyPropertyChanged(string propertyname)
        {
            if (null != PropertyChanged)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
        }
    }
}
